<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>InitPHP框架 PHP框架 - A PHP Framework - Cache API</title>
<link href="static/common.css" type="text/css" rel="stylesheet" />
<meta name="keywords" content="php框架，国产php框架, initphp框架，MVC，分层体系" />
<meta name="description" content="initphp框架是一款国产php框架。initphp框架主要基于MVC模式，具备代码清晰，操作简单，功能齐全，开发快速，高效安全等特点，是您选择php框架的首选。" />
</head>
<body>
<div class="header">
  <div class="header_nav">InitPHP (A PHP Framework) 用户手册</div>
  <div class="header_div">
    <div class="header_title">第6章 6.5.3 Sql Build API</div>
    <div class="header_right"><a href="6_5_2.htm">上一页</a> <a href="6_5_4.htm">下一页</a> </div>
  </div>
</div>
<div class="title">目录</div>
<ul style="list-style:none;">
  <li><a href="#$this->dao->db->build_escape">$this->dao->db->build_escape</a></li>
  <li><a href="#$this->dao->db->build_implode">$this->dao->db->build_implode</a></li>
  <li><a href="#$this->dao->db->build_in">$this->dao->db->build_in</a></li>
  <li><a href="#$this->dao->db->build_insert">$this->dao->db->build_insert</a></li>
  <li><a href="#$this->dao->db->build_insertmore">$this->dao->db->build_insertmore</a></li>
  <li><a href="#$this->dao->db->build_limit">$this->dao->db->build_limit</a></li>
   <li><a href="#$this->dao->db->build_kv">$this->dao->db->build_kv</a></li>
  <li><a href="#$this->dao->db->build_update">$this->dao->db->build_update</a></li>
   <li><a href="#$this->dao->db->build_where">$this->dao->db->build_where</a></li>
      <li><a href="#$this->dao->db->build_key">$this->dao->db->build_key</a></li>
</ul>
<div class="nav"></div>

<div class="title">1. $this->dao->db->build_escape($val, $iskey = 0) SQL组装-单个或数组参数过滤<a name="$this->dao->db->build_escape"></a></div>
<div class="title">
  <h3>接口描述：</h3>
</div>
<p>  SQL组装-单个或数组参数过滤。在Dao中使用</p>
<div class="title">
  <h3>参数：</h3>
</div>
<table>
  <tr>
    <th style="width:20%;"> 参数 </th>
    <th style="width:20%;"> 类型 </th>
    <th style="width:10%;"> 是否必须 </th>
    <th style="width:50%;"> 描述 </th>
  </tr>
    <tr>
      <td>$val</td>
      <td>String|Array </td>
      <td>是</td>
      <td>SQL组装数据</td>
    </tr>
	    <tr>
      <td>$iskey</td>
      <td>Int </td>
      <td>否</td>
      <td>0-过滤value值，1-过滤字段</td>
    </tr>
</table>
<div class="title">
  <h3>使用：</h3>
</div>
<pre id="PHP" class="prettyprint">
class testaDao extends Dao {
	
	public $db = 'test';
	public function test() {
		echo $this->dao->db->build_escape($val, $iskey = 0);
	}
}
</pre>
<div class="nav"></div>

<div class="title">2. $this->dao->db->build_implode($val, $iskey = 0) SQL组装-将数组值通过，隔开<a name="$this->dao->db->build_implode"></a></div>
<div class="title">
  <h3>接口描述：</h3>
</div>
<p>  SQL组装-将数组值通过，隔开 。在Dao中使用</p>
<div class="title">
  <h3>参数：</h3>
</div>
<table>
  <tr>
    <th style="width:20%;"> 参数 </th>
    <th style="width:20%;"> 类型 </th>
    <th style="width:10%;"> 是否必须 </th>
    <th style="width:50%;"> 描述 </th>
  </tr>
    <tr>
      <td>$val</td>
      <td>Array </td>
      <td>是</td>
      <td>SQL组装数据,返回：'1','2','3'</td>
    </tr>
	 <tr>
      <td>$iskey</td>
      <td>Int </td>
      <td>否</td>
      <td>0-过滤value值，1-过滤字段</td>
    </tr>
</table>
<div class="title">
  <h3>使用：</h3>
</div>
<pre id="PHP" class="prettyprint">
class testaDao extends Dao {
	
	public $db = 'test';
	public function test() {
		echo $this->dao->db->build_implode(array('test' => 'test1'), $iskey = 0);
	}
}
</pre>
<div class="nav"></div>

<div class="title">3. $this->dao->db->build_in($val) SQL组装-组装IN语句<a name="$this->dao->db->build_in"></a></div>
<div class="title">
  <h3>接口描述：</h3>
</div>
<p>   SQL组装-组装IN语句 。在Dao中使用</p>
<div class="title">
  <h3>参数：</h3>
</div>
<table>
  <tr>
    <th style="width:20%;"> 参数 </th>
    <th style="width:20%;"> 类型 </th>
    <th style="width:10%;"> 是否必须 </th>
    <th style="width:50%;"> 描述 </th>
  </tr>
    <tr>
      <td>$val</td>
      <td>String|Array </td>
      <td>是</td>
      <td>SQL组装数据, 例如：ID:array(1,2,3)。返回：('1','2','3')</td>
    </tr>
</table>
<div class="title">
  <h3>使用：</h3>
</div>
<pre id="PHP" class="prettyprint">
class testaDao extends Dao {
	
	public $db = 'test';
	public function test() {
		echo $this->dao->db->build_in(array(2,3,4));
	}
}
</pre>
<div class="nav"></div>

<div class="title">4. $this->dao->db->build_insert($val) SQL组装-组装INSERT语句<a name="$this->dao->db->build_insert"></a></div>
<div class="title">
  <h3>接口描述：</h3>
</div>
<p>   SQL组装-组装IN语句 。在Dao中使用</p>
<div class="title">
  <h3>参数：</h3>
</div>
<table>
  <tr>
    <th style="width:20%;"> 参数 </th>
    <th style="width:20%;"> 类型 </th>
    <th style="width:10%;"> 是否必须 </th>
    <th style="width:50%;"> 描述 </th>
  </tr>
    <tr>
      <td>$value</td>
      <td>String </td>
      <td>是</td>
      <td>参数规则：array('key' => 'value')，返回：(id,username) VALUES ('ss', 'sadsa')</td>
    </tr>
</table>
<div class="title">
  <h3>使用：</h3>
</div>
<pre id="PHP" class="prettyprint">
class testaDao extends Dao {
	
	public $db = 'test';
	public function test() {
		echo $this->dao->db->build_insert( array('key' => 'value'));
	}
}
</pre>
<div class="nav"></div>

<div class="title">5. $this->dao->db->build_insertmore($field, $data) SQL组装-组装多条语句插入<a name="$this->dao->db->build_insertmore"></a></div>
<div class="title">
  <h3>接口描述：</h3>
</div>
<p>  SQL组装-组装多条语句插入。在Dao中使用</p>
<div class="title">
  <h3>参数：</h3>
</div>
<table>
  <tr>
    <th style="width:20%;"> 参数 </th>
    <th style="width:20%;"> 类型 </th>
    <th style="width:10%;"> 是否必须 </th>
    <th style="width:50%;"> 描述 </th>
  </tr>
    <tr>
      <td>$field</td>
      <td>Array </td>
      <td>是</td>
      <td>字段</td>
    </tr>
	    <tr>
      <td>$value</td>
      <td>Array </td>
      <td>是</td>
      <td>值：array(array('test1'),array('test2'))，返回：('key') VALUES ('value'),('value2')</td>
    </tr>
</table>
<div class="title">
  <h3>使用：</h3>
</div>
<pre id="PHP" class="prettyprint">
class testaDao extends Dao {
	
	public $db = 'test';
	public function test() {
		echo $this->dao->db->build_insertmore(array('username'), array(array('zhuli'), array('woshishen')));
	}
}
</pre>
<div class="nav"></div>


<div class="title">6. $this->dao->db->build_kv($k, $v) SQL组装-组装KEY=VALUE形式<a name="$this->dao->db->build_kv"></a></div>
<div class="title">
  <h3>接口描述：</h3>
</div>
<p>  SQL组装-组装多条语句插入。在Dao中使用</p>
<div class="title">
  <h3>参数：</h3>
</div>
<table>
  <tr>
    <th style="width:20%;"> 参数 </th>
    <th style="width:20%;"> 类型 </th>
    <th style="width:10%;"> 是否必须 </th>
    <th style="width:50%;"> 描述 </th>
  </tr>
    <tr>
      <td>$k</td>
      <td>String</td>
      <td>是</td>
      <td>KEY值</td>
    </tr>
	    <tr>
      <td>$v</td>
      <td>String</td>
      <td>是</td>
      <td>VALUE值  返回：a = 'a'</td>
    </tr>
</table>
<div class="title">
  <h3>使用：</h3>
</div>
<pre id="PHP" class="prettyprint">
class testaDao extends Dao {
	
	public $db = 'test';
	public function test() {
		echo $this->dao->db->build_kv('asd', 'asdas');
	}
}
</pre>
<div class="nav"></div>

<div class="title">7. $this->dao->db->build_limit($start, $num = NULL) SQL组装-组装LIMIT语句<a name="$this->dao->db->build_limit"></a></div>
<div class="title">
  <h3>接口描述：</h3>
</div>
<p> SQL组装-组装LIMIT语句。在Dao中使用</p>
<div class="title">
  <h3>参数：</h3>
</div>
<table>
  <tr>
    <th style="width:20%;"> 参数 </th>
    <th style="width:20%;"> 类型 </th>
    <th style="width:10%;"> 是否必须 </th>
    <th style="width:50%;"> 描述 </th>
  </tr>
    <tr>
      <td>$start</td>
      <td>Int </td>
      <td>是</td>
      <td>开始</td>
    </tr>
	    <tr>
      <td>$num</td>
      <td>Int </td>
      <td>是</td>
      <td>条数  返回：LIMIT 0,10 </td>
    </tr>
</table>
<div class="title">
  <h3>使用：</h3>
</div>
<pre id="PHP" class="prettyprint">
class testaDao extends Dao {
	
	public $db = 'test';
	public function test() {
		echo $this->dao->db->build_limit(100,200);
	}
}
</pre>
<div class="nav"></div>

<div class="title">8. $this->dao->db->build_update($val) SQL组装-组装UPDATE语句<a name="$this->dao->db->build_update"></a></div>
<div class="title">
  <h3>接口描述：</h3>
</div>
<p>SQL组装-组装UPDATE语句 。在Dao中使用</p>
<div class="title">
  <h3>参数：</h3>
</div>
<table>
  <tr>
    <th style="width:20%;"> 参数 </th>
    <th style="width:20%;"> 类型 </th>
    <th style="width:10%;"> 是否必须 </th>
    <th style="width:50%;"> 描述 </th>
  </tr>
    <tr>
      <td>$val</td>
      <td>Array </td>
      <td>是</td>
      <td>数组参数，返回：SET name = 'aaaaa'</td>
    </tr>
</table>
<div class="title">
  <h3>使用：</h3>
</div>
<pre id="PHP" class="prettyprint">
class testaDao extends Dao {
	
	public $db = 'test';
	public function test() {
		echo $this->dao->db->build_update(array('username' => 'asdas'));
	}
}
</pre>
<div class="nav"></div>

<div class="title">9. $this->dao->db->build_where($val) SQL组装-组装AND符号的WHERE语句 <a name="$this->dao->db->build_where"></a></div>
<div class="title">
  <h3>接口描述：</h3>
</div>
<p> SQL组装-组装AND符号的WHERE语句 。在Dao中使用</p>
<div class="title">
  <h3>参数：</h3>
</div>
<table>
  <tr>
    <th style="width:20%;"> 参数 </th>
    <th style="width:20%;"> 类型 </th>
    <th style="width:10%;"> 是否必须 </th>
    <th style="width:50%;"> 描述 </th>
  </tr>
    <tr>
      <td>$val</td>
      <td>Array </td>
      <td>是</td>
      <td>数组参数，返回：WHERE a = 'a' AND b = 'b'</td>
    </tr>
</table>
<div class="title">
  <h3>使用：</h3>
</div>
<pre id="PHP" class="prettyprint">
class testaDao extends Dao {
	
	public $db = 'test';
	public function test() {
		// WHERE `sad` = 100
		echo $this->dao->db->build_where(array('sad'=>100));
		// WHERE `age` IN ('15', '18', '19')
		echo $this->dao->db->build_where(array('age'=>array(15,18,19)));
		// WHERE `age`>15 AND `age`<20
		echo $this->dao->db->build_where(array('age'=>array('>'=>15, '<'=>20)));
		// WHERE `age` like '%sad%'
		echo $this->dao->db->build_where(array('name'=>array('like'=>'%sad%')));
	}
}
</pre>
<div class="nav"></div>

<div class="title">10. $this->dao->db->build_key($val) 检查DAO中进来的数组参数是否key键存在 <a name="$this->dao->db->build_key"></a></div>
<div class="title">
  <h3>接口描述：</h3>
</div>
<p>检查DAO中进来的数组参数是否key键存在</p>
<div class="title">
  <h3>参数：</h3>
</div>
<table>
  <tr>
    <th style="width:20%;"> 参数 </th>
    <th style="width:20%;"> 类型 </th>
    <th style="width:10%;"> 是否必须 </th>
    <th style="width:50%;"> 描述 </th>
  </tr>
    <tr>
      <td>$data</td>
      <td>Array </td>
      <td>是</td>
      <td>数组结构，例如：array("username" => 'asdasd')</td>
    </tr>
	    <tr>
      <td>$fields</td>
      <td>String </td>
      <td>是</td>
      <td>例如："username,password"</td>
    </tr>
</table>
<div class="title">
  <h3>使用：</h3>
</div>
<pre id="PHP" class="prettyprint">
class userDao extends Dao {
	
	public $table_name = 'user';
	private $fields = "username,password";
	
	/**
	 * 新增用户
	 * @param $user
	 */
	public function addUser($user) {
		$user = $this->dao->db->build_key($user, $this->fields);
		return $this->dao->db->insert($user, $this->table_name);
	}
}
</pre>
<div class="nav"></div>


<div class="footer">版权所有：<a href="">http://initphp.com</a> InitPHP (A PHP Framework) By @Aliyun_zhuli</div>
<script src="static/jquery.js" type="text/javascript"></script>
<link href="static/prettify/prettify.css" rel="stylesheet" type="text/css">
<script src="static/prettify/prettify.js" type="text/javascript"></script>
<script type="text/javascript" src="static/comm.js"></script>
</body>
</html>